initBatPrice = function(){
	$( "#bat_plice" ).dialog({
		  title:'批量添加',
	      autoOpen: false,
	      height: 400,
	      width: 750,
	      resizable:false,
	      modal: true,
	      buttons: {
	        "确定": function() {submitBatPrice();},
	        "取消": function() {
		        $(this).dialog('close');
		    }
	      }
	});
};
addIndex = 0;
addBatPrice = function(){
	$( "#bat_plice" ).dialog('open');
	addIndex = 0;
	$('#bat_plice tbody').html('');
	addBatPriceCell();
};
addBatPriceCell = function(){
	html = '';
	html+="<tr id = \'ticket_price_"+addIndex+"\'>";
	html+="	<td>";
	html+="		<input name = \'data["+addIndex+"][TicketPrice][ticket_id]\' type = \'hidden\' value = \'"+ticket_id+"\'/>";
	html+="		<input name = \'data["+addIndex+"][TicketPrice][showtime]\' value = \'"+ticket_date+"\' class = 'time'></td>";
	html+="	<td><input name = \'data["+addIndex+"][TicketPrice][price]\' value = \'\' class = \'input_short price\'></td>";
	html+="	<td><input name = \'data["+addIndex+"][TicketPrice][eprice]\' value = \'\' class = \'input_short\'></td>";
	html+="	<td><input name = \'data["+addIndex+"][TicketPrice][spt_eticket]\' value = \'1\' type = \'checkbox\'></td>";
	html+="	<td><input name = \'data["+addIndex+"][TicketPrice][description]\' value = \'\' ></td>";
	html+="	<td><select name = \'data["+addIndex+"][TicketPrice][ticket_price_state_id]\'  value = \'100\' class = \'input_short\'>";
	html+= price_state_options;
	html+=" </select></td>";
	html+="	<td><input name = \'data["+addIndex+"][TicketPrice][sort]\'  value = \'100\' class = \'input_short\'></td>";
	html+="	<td><a href = \'javascript:;\' onclick = \'delBarPriceCell("+addIndex+")\'>删除</a></td>";
	html+="</tr>";
	addIndex++;
	$('#bat_plice tbody').append(html);
};
delBarPriceCell = function(id){
	$('#ticket_price_'+id).remove();
};

checkBatPrice = function(){
	err = 0;
	$('#bat_plice .time,#bat_plice .price').each(function(){
		tar = $(this); 
		if(tar.val() == ''){
			tar.addClass('error');
			err++;
		}else{
			tar.removeClass('error');
		}
	});
	if(err == 0){
		return true;
	}
	return false;
}

submitBatPrice = function(){
	if(checkBatPrice()){
		$.ajax({
		  type: "post",
		  url: 'admin/TicketPrices/batprice/'+ticket_id,
		  data:$('#bat_plice form').serializeObject(),
		  dataType:'json',
		}).done(function( msg ) {
			if(msg.state){
				alert(msg.msg);
				$( "#bat_plice" ).dialog('close');
			}else{
				alert(msg.msg);
			}
		});
	}
};

delbat = function(id){
	var ids = [];
	if(id){
		$('.select_sigle').attr('checked',false);
		$('.select_sigle[value='+id+']').attr('checked',true);
	}
	$('.select_sigle:checked').each(function(i){
		ids[i] = $(this).val();
	});
	if(ids.length == 0){
		alert('请选择要删除的价格id');
	}else{
		if (confirm("确定要删除所选的 "+ids.length+" 个价格吗？删除后将不可恢复")) { 
			$.ajax({
			  type: "post",
			  url: 'admin/TicketPrices/delete/'+ticket_id,
			  data:{data:ids},
			  dataType:'json',
			}).done(function( msg ) {
				if(msg.state){
					alert(msg.msg);
					location.reload();
				}else{
					alert(msg.msg);
				}
			}); 
		}else{
			if(id){
				$('.select_sigle[value='+id+']').attr('checked',false);
			}
		}
	}
	console.log(ids);
};
